// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './router/index'
import "../static/reset.css"
import {routerMode} from "./config/env"
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import axios from 'axios'
import VueAxios from 'vue-axios'
import promise from 'es6-promise'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import MetaInfo from 'vue-meta-info'

Vue.use(MetaInfo)
promise.polyfill()
Vue.use(VueAxios, axios)
Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.config.productionTip = false

/* eslint-disable no-new */
const router = new VueRouter({
  routes,
  mode: routerMode,
});

const whiteList = ['/index', '/workDetail', '/aboutUs', '/news', '/newsDetail', '/aboutUs', '/contactUs', '/introduce', '/forgetPwd', '/register', '/login', '/modify-pwd-success'];

router.beforeEach((to, form, next) => {
  NProgress.start();
  /*路由变化修改title*/
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  /*未登录拦截*/
  if (whiteList.indexOf(to.path) !== -1) {
    next();
  } else {
    if (sessionStorage.getItem("userWand")) {
      next();
    } else {
      next({path: '/login'});
    }
  }
});

router.afterEach(() => {
  NProgress.done();
});

/* eslint-disable no-new */
let apple = new Vue({
  router
}).$mount('#app');

export default apple;
